import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;


public class UAV {
		
	double longitude,latitude;
	int x,y;
	Panel delegatePanel;
	BufferedImage[] blinker;
	BufferedImage icon;
	
	//sprite sheet definitions
	final int width = 100;
	final int height = 100;
	final int rows = 1;
	final int cols = 5;
	int spritePointer  = 0;
	
	public UAV(Panel $delegate) throws IOException{
		delegatePanel = $delegate;
		x = $delegate.sizeX/2;
		y = $delegate.sizeY/2;
	
		icon = ImageIO.read(new File("res//uav.png"));
		
		BufferedImage spriteSheet = ImageIO.read(new File("res//blinker.png"));
		// The above line throws an checked IOException which must be caught.
		
		
		
		blinker = new BufferedImage[rows * cols];

		for (int i = 0; i < rows; i++)
		{
		    for (int j = 0; j < cols; j++)
		    {
		    	blinker[(i * cols) + j] = spriteSheet.getSubimage(
		            j * width,
		            i * height,
		            width,
		            height
		        );
		    }
		}
	}
	
	public BufferedImage drawBlinker(){
		
		if(spritePointer >=cols*5){
			spritePointer = 0;
		}
		
		if(spritePointer >= cols){//break between blinks 	
			return blinker[0];
		}
		
		return blinker[spritePointer];
		
	}
	
	public void setCoordinates(float _latitude, float _longitude){
		latitude = _latitude;
		longitude = _longitude;
		
		translate();
	}
	
	public void translate(){
		
		
		y = delegatePanel.sizeY/2 + (int)((delegatePanel.latitude - latitude)/delegatePanel.scaleLatPPY);
		x = delegatePanel.sizeX/2 + (int)((longitude - delegatePanel.longitude)/delegatePanel.scaleLonPPX);
		
		
	}
	
	
	
	
}
